<?php

namespace common\models;

use Yii;
use common\models\ResClasObjectModel;
use yii\data\Pagination;
/**
 * This is the model class for table "resource".
 *
 * @property integer $id
 * @property integer $ressubjectid
 * @property integer $restypeid
 * @property integer $resobjectid
 * @property string $Title
 * @property string $content
 * @property string $Language
 * @property string $Description
 * @property string $keywords
 * @property string $Contribute
 * @property string $Meta-Metadata
 * @property string $format
 * @property string $LearningResourceType
 * @property string $purpose
 * @property string $taxonpath
 * @property double $size
 * @property string $copyright
 * @property string $annotation
 */
class ResourceModel extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public $subject;
    public $grade;
    
    public static function tableName()
    {
        return 'resource';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['ressubjectid', 'restypeid', 'resobjectid'], 'integer'],
            [['size'], 'number'],
            [['title', 'content', 'language', 'description', 'keywords', 'contribute', 'Meta-Metadata', 'format', 'LearningResourceType', 'purpose', 'taxonpath', 'copyright', 'annotation'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'ressubjectid' => 'Ressubjectid',
            'restypeid' => 'Restypeid',
            'resobjectid' => 'Resobjectid',
            'title' => 'Title',
            'content' => 'Content',
            'Language' => 'Language',
            'description' => 'Description',
            'keywords' => '关键字',
            'contribute' => 'Contribute',
            'Meta-Metadata' => 'Meta  Metadata',
            'format' => 'Format',
            'LearningResourceType' => 'Learning Resource Type',
            'purpose' => 'Purpose',
            'taxonpath' => 'Taxonpath',
            'size' => 'Size',
            'copyright' => 'Copyright',
            'annotation' => 'Annotation',
            'subject'=>'学科',
            'grade'=>'年级'
        ];
    }
    
    public function getSearch($data,$pageSize)
    {
        //返回两个值$pager,$data
        $mygrade= $data['ResourceModel']['grade'];
        $gradeid= ResClasObjectModel::find()->where('idname=:iname',[':iname'=>$mygrade])->one()->resClasObjectID;
        $obj= self::find()->where('resobjectid =:oid',[':oid'=>$gradeid]);
        $count=$obj->count();
        $pager=new Pagination(['totalCount'=>$count,'pageSize'=>$pageSize]);
        $result=$obj->offset($pager->offset)->limit($pager->limit)->all();
//        var_dump($mygrade);var_dump($result);exit;
        $myData['data']=$result;
        $myData['pager']=$pager;
        return $myData;
       //数据查找
        //目前只是返回了数据，没有分页数组
        
    }
    
    public function getknowbyid($id)
    {
        $data= self::find()->where('id=:id',[':id'=>$id])->one();
        return $data;
    }

}
